package neuralNetwork.execution;

import java.util.Collection;

import neuralModel.neuron.INeuron;
import neuralNetwork.INeuralNetwork;

public class NeuralNetworkExecutor implements INeuralNetworkExecutor
{

	private INeuralNetwork neuralNetwork;

	public NeuralNetworkExecutor()
	{
	}

	public NeuralNetworkExecutor(INeuralNetwork neuralNetwork)
	{
		setNeuralNetwork(neuralNetwork);
	}

	@Override
	public INeuralNetwork getNeuralNetwork()
	{
		return neuralNetwork;
	}

	@Override
	public void setNeuralNetwork(INeuralNetwork neuralNetwork)
	{
		this.neuralNetwork = neuralNetwork;
	}

	@Override
	public void performTimeSteps(int stepCount)
	{
		for (int i = 0; i < stepCount; i++)
			performTimeStep();
	}

	@Override
	public void performTimeStep()
	{
		if (neuralNetwork != null)
		{
			Collection<INeuron> neurons = neuralNetwork.getNeuronMap().values();
			for (INeuron neuron : neurons)
			{
				neuron.updateInducedLocalField();
				neuron.updateOutputValue();
			}

			for (INeuron neuron : neurons)
			{
				neuron.driveOutputValue();
			}
		}
	}

}
